package org.lebutch.sw.activity;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import org.lebutch.sw.Constants;
import org.lebutch.sw.R;
import org.lebutch.sw.SevenWondersApp;

import wonder.Board;
import wonder.BoardInitialResource;

public class BoardActivity extends Activity {
    public static final String BOARD_ID = "org.lebutch.sw.activity.Board";

    private SevenWondersApp app;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.board);

        app = (SevenWondersApp)getApplication();

        Board board = (Board)getIntent().getExtras().getSerializable(BOARD_ID);
        Log.i(Constants.LOG_TAG, "Showing board: " + board.toString());

        TextView tv = (TextView)findViewById(android.R.id.text1);
        String text = String.format(getResources().getString(R.string.board_title_1),
                board.getName(), board.getSide());
        tv.setText(text);

        tv = (TextView)findViewById(R.id.initialResource);
        BoardInitialResource ir = board.getInitialResource();
        text = String.format(getResources().getString(R.string.resource_info), getResources()
                .getString(app.getIdentifier(ir.getResourceType().name())), ir.getQuantity(),
                getResources().getString(app.getIdentifier(ir.getUsageType().name())));
        tv.setText(text);

        Drawable drw = app.getResourceDrawable(BoardActivity.this, ir.getResourceType());
        if (drw != null) {
            ImageView iv = (ImageView)findViewById(R.id.imageResource);
            iv.setImageDrawable(drw);
            iv.setMaxHeight(drw.getIntrinsicHeight());
        }

        drw = app.getBoardStepsDrawable(BoardActivity.this, board);
        if (drw != null) {
            ImageView iv = (ImageView)findViewById(R.id.imageWonder);
            iv.setImageDrawable(drw);
            iv.setMaxWidth(drw.getIntrinsicWidth());
        }
    }
}
